﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace ASPItalia.ModelVirtualCasting.Silverlight.Helpers
{
  public class Helper
  {
      public static string BaseImageRepositoryUri = "http://localhost:39956/Images/";
    public static string BaseUri = string.Empty;

    public static string GetBaseUri(string absoluteDocumentPath)
    {
      string baseUri = string.Empty;

      //solo il thread UI può accedere a HtmlPage
      try
      {
        baseUri = HtmlPage.Document.DocumentUri.AbsoluteUri;
      }
      catch
      {
      }

      int lastSlash = baseUri.LastIndexOf("/");
      if (lastSlash > 1)
      {
        int character = baseUri.Length - lastSlash;
        if (character > 1)
        {
          baseUri = baseUri.Remove(lastSlash, character);
        }
      }

      baseUri = String.Format("{0}{1}", baseUri, absoluteDocumentPath);

      BaseUri = baseUri;

      return baseUri;
    }
  }
}
